package leetcode;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

public class TestCalculate {

    /**
     * 判断加法是否相等
     */
    @Test
    public void test1(){
        // 1+1
        int result = Calculate.addHandler(1, 1);
        // 预期结果为2
        Assertions.assertEquals(3,result,"计算结果错误");
    }

    /**
     * 判断减法 结果是否不相等
     */
    @Test
    public void test2(){
        // 1-1
        int result = Calculate.subtractHandler(1, 1);
        // 预期结果为 除了0 之外的数
        Assertions.assertNotEquals(0,result,"计算结果错误");
    }

    /**
     * 判断乘法 数组是否相等
     */
    @Test
    public void test3(){
        //
        int result = Calculate.multiplyHandler(1,1);
        int [] nums1 = {result};
        int [] nums2 = {result,result};
        // 预期结果不相等
        Assertions.assertArrayEquals(nums1,nums2,"数组不相等");
    }

    /**
     * 判断除法
     */
    @Test
    public void test4(){
        // 1/1
        int result = Calculate.divideHandler(1, 1);
        String str = String.valueOf(result);
        String prefix = "1";
        // 预期结果为前缀相等
        boolean res = str.startsWith(prefix);
        System.out.println(res); //true
    }


    private String str;
    private int length;

    // @Paramters(name = "{index}: str={0}, length={1}")
    public static Iterable<Object[]> data() {
        return Arrays.asList(new Object[][]{
                {"Hello", 5},
                {"World", 5},
                {"JUnit", 4}
        });
    }

    public void JunitTest4(String str, int length) {
        this.str = str;
        this.length = length;
    }

    @Test
    public void testLength() {
        Assertions.assertEquals(length, str.length());
    }

}
